    using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Ent.Web;
using Ent.Web.Helper;
using Ent.Web.WebControl;
using Ent.Web.WebControl.Parameters;

public partial class Controls_ContentSettings : Ent.Web.WebControl.UserControl
{
    private Settings _pop;
    int minNomCount = 1;
    int minNomAmt = 0;
    int maxNomAmt = 99999;
    int minSpAmt = 1;
    int maxSpAmt = 99999;
    public Controls_ContentSettings()
    {
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Dictionary<string, string> rep = new Dictionary<string, string>();

        #region Voting

        TimeSpan tSpan = DateTime.Parse(Session["EndDate"].ToString()).Subtract(DateTime.Today);
        double midTime = tSpan.Days / 2;
        string voteStDt = DateTime.Today.AddDays(midTime).ToShortDateString();
        txtVoteStDate.Text = voteStDt;

        rvVoteStDate.MaximumValue = voteStDt;
        rvVoteStDate.MinimumValue = DateTime.Today.ToShortDateString();
        rep = new Dictionary<string, string>();
        rep.Add("$1", rvVoteStDate.MinimumValue);
        rep.Add("$2", rvVoteStDate.MaximumValue);
        rep.Add("$3", "Voting Start");
        rvVoteStDate.ErrorMessage = ResourceHelper.Get("MSG_RVDueDate", rep);

        rep = new Dictionary<string, string>();
        rep.Add("$1", "Voting Start Date");
        rfvVoteStDate.ErrorMessage = ResourceHelper.Get("MSG_RFVRequired", rep);

        #endregion
        #region Sponsor
        rvSponcerStData.MaximumValue = DateTime.Today.AddMonths(Ent.Web.Helper.MathFunction.ConvertToInteger(GetASPXParam("maxDuration"))).ToShortDateString();
        rvSponcerStData.MinimumValue = DateTime.Today.ToShortDateString();
        rep = new Dictionary<string, string>();
        rep.Add("$1", rvSponcerStData.MinimumValue);
        rep.Add("$2", rvSponcerStData.MaximumValue);
        rep.Add("$3", "Sponsor Start");
        rvSponcerStData.ErrorMessage = ResourceHelper.Get("MSG_RVDueDate", rep);

        rep = new Dictionary<string, string>();
        rep.Add("$1", "Sponsor Start Date");
        rfvSponcerStData.ErrorMessage = ResourceHelper.Get("MSG_RFVRequired", rep);

        rep = new Dictionary<string, string>();
        rep.Add("$1", "Minimum Sponsor Amount");
        rfvMinSponsor.ErrorMessage = ResourceHelper.Get("MSG_RFVRequired", rep);

        rvMinSponsor.MaximumValue = maxSpAmt.ToString();
        rvMinSponsor.MinimumValue = minSpAmt.ToString();
        rep = new Dictionary<string, string>();
        rep.Add("$1", rvMinSponsor.MinimumValue);
        rep.Add("$2", rvMinSponsor.MaximumValue);
        rep.Add("$3", "Minimum Sponsor Amount");
        rvMinSponsor.ErrorMessage = ResourceHelper.Get("MSG_RVMaxCount", rep);

        txtSponcerStData.Text = DateTime.Today.ToShortDateString();
        #endregion
        #region Nomination
        rvParticipationStDate.MaximumValue = DateTime.Today.AddMonths(Ent.Web.Helper.MathFunction.ConvertToInteger(GetASPXParam("maxDuration"))).ToShortDateString();
        rvParticipationStDate.MinimumValue = DateTime.Today.ToShortDateString();
        rep = new Dictionary<string, string>();
        rep.Add("$1", rvParticipationStDate.MinimumValue);
        rep.Add("$2", rvParticipationStDate.MaximumValue);
        rep.Add("$3", "Nomination Start");
        rvParticipationStDate.ErrorMessage = ResourceHelper.Get("MSG_RVDueDate", rep);

        
        rep = new Dictionary<string, string>();
        rep.Add("$1", "Nomination Start Date");
        rfvParticipationStDate.ErrorMessage = ResourceHelper.Get("MSG_RFVRequired", rep);

        object maxNomCount = GetASPXParam("maxNomCount");
        rvMaxPartLimit.MaximumValue = maxNomCount != null ? maxNomCount.ToString() : "";
        rvMaxPartLimit.MinimumValue = minNomCount.ToString();
        rep = new Dictionary<string, string>();
        rep.Add("$1", rvMaxPartLimit.MinimumValue);
        rep.Add("$2", rvMaxPartLimit.MaximumValue);
        rep.Add("$3", "Maximum Nomination Count");
        rvMaxPartLimit.ErrorMessage = ResourceHelper.Get("MSG_RVMaxCount", rep);

        rep = new Dictionary<string, string>();
        rep.Add("$1", "Limited");
        rep.Add("$2", "Maximum Nomination Count");
        rfvMaxPartLimit.ErrorMessage = ResourceHelper.Get("MSG_RFVMaxCount", rep);

        cvParticipationStDate.ErrorMessage = ResourceHelper.Get("MSG_NomVote");

        rep = new Dictionary<string, string>();
        rep.Add("$1", "Nomination Amount");
        rfvNomAmount.ErrorMessage = ResourceHelper.Get("MSG_RFVRequired", rep);

        rvNomAmount.MaximumValue = maxNomAmt.ToString();
        rvNomAmount.MinimumValue = minNomAmt.ToString();
        rep = new Dictionary<string, string>();
        rep.Add("$1", rvNomAmount.MinimumValue);
        rep.Add("$2", rvNomAmount.MaximumValue);
        rep.Add("$3", "Nomination Amount");
        rvNomAmount.ErrorMessage = ResourceHelper.Get("MSG_RVMaxCount", rep);

        txtParticipationStDate.Text = DateTime.Today.ToShortDateString();

        btnShowCal.Attributes.Add("onclick", "show_cal(400, 160, this, '" + txtVoteStDate.ClientID + "');");
        btnShowCal2.Attributes.Add("onclick", "show_cal(400, 160, this, '" + txtParticipationStDate.ClientID + "');");
        btnShowCal3.Attributes.Add("onclick", "show_cal(400, 160, this, '" + txtSponcerStData.ClientID + "');");
        #endregion

        PopuplateControls();
    }
    public override void AddJavascript()
    {
        try
        {
            LoadJavascript("Javascripts/Settings.js");
            LoadJavascript("Javascripts/calendar.js");
            divJavascript.InnerHtml += JavascriptText;
        }
        catch (Exception exc)
        { }
    }
    public void PopuplateControls()
    {
        _pop = new Settings(Server.MapPath("Data/Settings.xml"));
        ddlCurrency.Items.AddRange(_pop.GetItemCollection("Currency"));
        cblVoterTracking.Items.AddRange(_pop.GetItemCollection("UserTracking"));
        cblMandatory.Items.AddRange(_pop.GetItemCollection("Mandatory"));
        cblNomineeTracking.Items.AddRange(_pop.GetItemCollection("UserTracking"));
        cblFileType.Items.AddRange(_pop.GetItemCollection("FileType"));
        rblMaxPart.Items.AddRange(_pop.GetItemCollection("MaxParticipation"));
    }
    public override void SetEvents()
    {
        #region Sponsor
        if (cbSponcership.Checked)
        {
            OnLoadEnable("tabSponsorship");
            OnLoadExecute(new string[] { 
                "_ValidatorEnable(document.getElementById('" + rvSponcerStData.ClientID + "'),true)" ,
                "_ValidatorEnable(document.getElementById('" + rfvSponcerStData.ClientID + "'),true)",
                "_ValidatorEnable(document.getElementById('" + rfvMinSponsor.ClientID + "'),true)" ,
                "_ValidatorEnable(document.getElementById('" + rvMinSponsor.ClientID + "'),true)" 
            });
        }
        else
        {
            OnLoadDisable("tabSponsorship");
            OnLoadExecute(new string[] { 
                "_ValidatorEnable(document.getElementById('" + rvSponcerStData.ClientID + "'),false)" ,
                "_ValidatorEnable(document.getElementById('" + rfvSponcerStData.ClientID + "'),false)",
                "_ValidatorEnable(document.getElementById('" + rfvMinSponsor.ClientID + "'),false)" ,
                "_ValidatorEnable(document.getElementById('" + rvMinSponsor.ClientID + "'),false)" 
            });
        }
        
        SetOnClickEvent(new OnclickParam(cbSponcership, null, "tabSponsorship", 
            new string[] { 
                "_ValidatorEnable(document.getElementById('" + rvSponcerStData.ClientID + "'),!document.getElementById('" + txtSponcerStData.ClientID + "').disabled)" ,
                "_ValidatorEnable(document.getElementById('" + rfvSponcerStData.ClientID + "'),!document.getElementById('" + txtSponcerStData.ClientID + "').disabled)",
                "_ValidatorEnable(document.getElementById('" + rfvMinSponsor.ClientID + "'),!document.getElementById('" + txtMinSponsor.ClientID + "').disabled)" ,
                "_ValidatorEnable(document.getElementById('" + rvMinSponsor.ClientID + "'),!document.getElementById('" + txtMinSponsor.ClientID + "').disabled)" 
                },
            null));
        #endregion
        #region Nomination
        if (cbParticipation.Checked)
        {
            OnLoadEnable("tabNomination");
            OnLoadExecute(new string[] { 
                "_ValidatorEnable(document.getElementById('" + rvParticipationStDate.ClientID + "'),true)" ,
                "_ValidatorEnable(document.getElementById('" + cvParticipationStDate.ClientID + "'),true)" ,
                "_ValidatorEnable(document.getElementById('" + rfvParticipationStDate.ClientID + "'),true)"
            });
        }
        else
        {
            OnLoadDisable("tabNomination");
            OnLoadExecute(new string[] { 
                "_ValidatorEnable(document.getElementById('" + rvParticipationStDate.ClientID + "'),false)" ,
                "_ValidatorEnable(document.getElementById('" + cvParticipationStDate.ClientID + "'),false)" ,
                "_ValidatorEnable(document.getElementById('" + rfvParticipationStDate.ClientID + "'),false)"
            });
        }
        if (cbParticipation.Checked && cbUpload.Checked)
            OnLoadEnable(cblFileType.ClientID);
        else
            OnLoadDisable(cblFileType.ClientID );

        if (cbParticipation.Checked && rblMaxPart.SelectedIndex == 1)
        {
            OnLoadEnable(txtMaxPartLimit.ClientID);
            OnLoadExecute(new string[] { 
                "_ValidatorEnable(document.getElementById('" + rfvMaxPartLimit.ClientID + "'),true)" ,
                "_ValidatorEnable(document.getElementById('" + rvMaxPartLimit.ClientID + "'),true)"
            });
        }
        else
        {
            OnLoadDisable(txtMaxPartLimit.ClientID);
            OnLoadExecute(new string[] { 
                "_ValidatorEnable(document.getElementById('" + rfvMaxPartLimit.ClientID + "'),false)" ,
                "_ValidatorEnable(document.getElementById('" + rvMaxPartLimit.ClientID + "'),false)"
            });
        }
        OnclickParam onclickMaxPart = new OnclickParam(rblMaxPart, rblMaxPart.ClientID + "_1", txtMaxPartLimit.ClientID, 
            new string[] { "_ValidatorEnable(document.getElementById('" + rfvMaxPartLimit.ClientID + "'),!document.getElementById('" + txtMaxPartLimit.ClientID + "').disabled)", 
                "_ValidatorEnable(document.getElementById('" + rvMaxPartLimit.ClientID + "'),!document.getElementById('" + txtMaxPartLimit.ClientID + "').disabled)" },
            null);
        OnclickParam onclickUpload = new OnclickParam(cbUpload, null, cblFileType.ClientID, null, null);
        SetOnClickEvent(new OnclickParam(cbParticipation, null, "tabNomination",
            new string[] { "_ValidatorEnable(document.getElementById('" + rfvMaxPartLimit.ClientID + "'),!document.getElementById('" + txtMaxPartLimit.ClientID + "').disabled)", 
                "_ValidatorEnable(document.getElementById('" + rvMaxPartLimit.ClientID + "'),!document.getElementById('" + txtMaxPartLimit.ClientID + "').disabled)",
                "_ValidatorEnable(document.getElementById('" + rfvParticipationStDate.ClientID + "'),!document.getElementById('" + txtParticipationStDate.ClientID + "').disabled)",
                "_ValidatorEnable(document.getElementById('" + rvParticipationStDate.ClientID + "'),!document.getElementById('" + txtParticipationStDate.ClientID + "').disabled)",
                "_ValidatorEnable(document.getElementById('" + cvParticipationStDate.ClientID + "'),!document.getElementById('" + txtParticipationStDate.ClientID + "').disabled)"
                }, 
            new OnclickParam[] { onclickMaxPart, onclickUpload }));
        SetOnClickEvent(onclickMaxPart);
        SetOnClickEvent(onclickUpload);
        #endregion
    }
    public override void Init()
    {
        foreach (string key in Values.Keys)
        {
            if (Values[key] == null)
                continue;
            string noIdkey = key.Replace(ID + "_", "");
            switch (noIdkey)
            {
                
                #region Voting
                case "cblVoterTracking":
                    SetCollectionControl(cblVoterTracking, (string[])Values[key]);
                    break;
                case "cblMandatory":
                    SetCollectionControl(cblMandatory, (string[])Values[key]);
                    break;
                case "txtVoteStDate":
                    txtVoteStDate.Text = (string)Values[key];
                    break;
                #endregion
                #region Sponsorship
                case "cbSponcership":
                    cbSponcership.Checked = Convert.ToBoolean(Values[key]);
                    break;
                case "txtSponcerStData":
                    txtSponcerStData.Text = (string)Values[key];
                    break;
                case "txtMinSponsor":
                    txtMinSponsor.Text = (string)Values[key];
                    break;
                #endregion
                #region Nomination
                case "cblNomineeTracking":
                    SetCollectionControl(cblNomineeTracking, (string[])Values[key]);
                    break;
                case "cbParticipation":
                    cbParticipation.Checked = Convert.ToBoolean(Values[key]);
                    break;
                case "txtParticipationStDate":
                    txtParticipationStDate.Text = (string)Values[key];
                    break;
                case "rblMaxPart":
                    SetCollectionControl(rblMaxPart, (string[])Values[key]);
                    break;
                case "txtMaxPartLimit":
                    txtMaxPartLimit.Text = (string)Values[key];
                    break;
                case "txtNomAmount":
                    txtNomAmount.Text = (string)Values[key];
                    break;
                case "ddlCurrency":
                    ddlCurrency.SelectedIndex = ddlCurrency.Items.IndexOf(ddlCurrency.Items.FindByValue(Values[key].ToString()));
                    break;
                case "cbUpload":
                    cbUpload.Checked = Convert.ToBoolean(Values[key]);
                    break;
                case "cblFileType":
                    SetCollectionControl(cblFileType, (string[])Values[key]);
                    break;
                #endregion
                default:
                    break;
            }
        }
    }
    public override void Dispose()
    {
        //throw new Exception("The method or operation is not implemented.");
    }
    public override Dictionary<string, object> GetValues()
    {
        Dictionary<string, object> retValue = new Dictionary<string, object>();
        
        #region Nomination
        retValue.Add(ID + "_cbParticipation", cbParticipation.Checked);
        retValue.Add(ID + "_txtParticipationStDate", txtParticipationStDate.Text);
        retValue.Add(ID + "_rblMaxPart", Ent.Web.WebControl.Helper.GetSelectedValues(rblMaxPart.Items));
        retValue.Add(ID + "_txtMaxPartLimit", txtMaxPartLimit.Text);
        retValue.Add(ID + "_txtNomAmount", txtNomAmount.Text);
        retValue.Add(ID + "_ddlCurrency", ddlCurrency.SelectedValue);
        retValue.Add(ID + "_cbUpload", cbUpload.Checked);
        retValue.Add(ID + "_cblFileType", Ent.Web.WebControl.Helper.GetSelectedValues(cblFileType.Items));
        retValue.Add(ID + "_cblNomineeTracking", Ent.Web.WebControl.Helper.GetSelectedValues(cblNomineeTracking.Items));
        #endregion
        #region Voting
        retValue.Add(ID + "_txtVoteStDate", txtVoteStDate.Text);
        retValue.Add(ID + "_cblMandatory", Ent.Web.WebControl.Helper.GetSelectedValues(cblMandatory.Items));
        retValue.Add(ID + "_cblVoterTracking", Ent.Web.WebControl.Helper.GetSelectedValues(cblVoterTracking.Items));
        #endregion
        #region Sponsorship
        retValue.Add(ID + "_cbSponcership", cbSponcership.Checked);
        retValue.Add(ID + "_txtSponcerStData", txtSponcerStData.Text);
        retValue.Add(ID + "_txtMinSponsor", txtMinSponsor.Text);
        #endregion
        
        return retValue;
    }
}

